# Contributor: Francesco Colista <fcolista@alpinelinux.org>
# Contributor: Jakub Jirutka <jakub@jirutka.cz>
# Maintainer: Francesco Colista <fcolista@alpinelinux.org>
pkgname=kitty
pkgver=0.25.2
pkgrel=0
pkgdesc="Modern, hackable, featureful, OpenGL based terminal emulator"
url="https://sw.kovidgoyal.net/kitty/"
arch="all"
license="GPL-3.0-only"
depends="less ncurses ncurses-terminfo-base py3-pygments"
checkdepends="ttf-dejavu"
makedepends="
	dbus-dev
	fontconfig-dev
	freetype-dev
	harfbuzz-dev
	lcms2-dev
	libcanberra-dev
	libpng-dev
	librsync-dev
	libxcursor-dev
	libxi-dev
	libxinerama-dev
	libxkbcommon-dev
	libxrandr-dev
	mesa-dev
	py3-setuptools
	python3-dev
	wayland-dev
	wayland-protocols
	zlib-dev
	"
install="$pkgname.post-install $pkgname.post-upgrade"
subpackages="$pkgname-wayland $pkgname-x11"
source="$pkgname-$pkgver.tar.gz::https://github.com/kovidgoyal/kitty/archive/v$pkgver.tar.gz
	fix-ppc64le-build-ioctl-with-musl.patch
	disable-docs.patch
	remove-failing-test.patch
	fix-tests.patch
	"

prepare() {
	default_prepare

	# Fix python shebangs.
	find -type f -name '*.py' -exec sed -Ei 's|/usr/bin/env python3?|/usr/bin/python3|g' '{}' \;
}

build() {
	# See https://github.com/void-linux/void-packages/issues/7975.
	export LDFLAGS="$LDFLAGS -Wl,-z,stack-size=2097152"

	python3 setup.py linux-package \
		--update-check-interval=0 \
		--verbose
}

check() {
	PATH="$builddir/linux-package/bin:$PATH" python3 setup.py test
}

package() {
	python3 setup.py linux-package --prefix "$pkgdir/usr"
}

wayland() {
	pkgdesc="Kitty GLFW backend for Wayland"
	depends="$pkgname=$pkgver-r$pkgrel wayland-libs-egl"
	install_if="$pkgname=$pkgver-r$pkgrel wayland-libs-server"

	amove usr/lib/kitty/kitty/glfw-wayland.so
}

x11() {
	pkgdesc="Kitty GLFW backend for X11"
	depends="$pkgname=$pkgver-r$pkgrel"
	install_if="$pkgname=$pkgver-r$pkgrel xorg-server"

	amove usr/lib/kitty/kitty/glfw-x11.so
}

sha512sums="
2bdf05d18af724983adad31cefeaa1ac3f41b59571b1f3b2cd2ab9915afc269ea36084e4ae69e45560c5ef1506b8459ae3e00a15d69bcd21e92213c45d8c828b  kitty-0.25.2.tar.gz
330f56f5fd60607c57f4f2cffdf33768b3af9e4c3e271a60a05cc3c653d70f7402af91ba0cdfe0257c8b4779884a6440eb52496078bce11799aaa1829ced9245  fix-ppc64le-build-ioctl-with-musl.patch
45222f0a06a9f5f8fc07b315e2abb01182443269e06f1e03b1383e8160f462871efc4af629cbc179f9d51c99ca4e10294b9b74b9b222ac985ba78f700b9e403e  disable-docs.patch
6978f874d22eed0091400b2480282779c79956f5235201e6989f0b42fdb27140fcb44aa070b607b177137fb6537f4f6e8ed52f5ca24181fd52f9b0f562b69998  remove-failing-test.patch
fe6b5c3ecabe006c38b58a84dd686b7da6ad473ebf1e304bfcf129fd6434fa139d345f1ab55344fd95e030c3b17fd821b74527621b7775bfad80ab5ecaad3759  fix-tests.patch
"
